package com.sykj.why.controller.front.album;

import com.sykj.why.exception.WhyException;
import com.sykj.why.handler.Response;
import com.sykj.why.mongo.dto.entity.AlbumTDTO;
import com.sykj.why.mongo.enums.exception.ResultEnum;
import com.sykj.why.mongo.service.AlbumTService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author Eleven
 * @date 2019/6/18
 * @desc 前端专辑控制访问层
 */

@RestController
@RequestMapping(value = "/front/album")
@Slf4j
@Api(value = "/front/album",description = "前端专辑控制访问层")
public class FrontAlbumController {

    @Autowired
    private AlbumTService albumTService;

    /**
     * 通过Id查找专辑
     * @param id
     * @return
     */
    @RequestMapping(value = "/findInfoById/{id}",method = RequestMethod.GET)
    @ApiOperation(value = "/findInfoById/{id}",notes = "通过Id查找专辑")
    public ResponseEntity findInfoById(@PathVariable String id){
        try {
            return Response.success("查询成功", albumTService.findInfoById(id));
        } catch (WhyException e) {
            return Response.serverError(e.getMessage(), e.getCode());
        } catch (Exception e) {
            log.error("通过Id查找专辑出现异常，{}", e.getMessage());
            return Response.serverError(ResultEnum.UNERROR.getMessage(), ResultEnum.UNERROR.getCode());
        }
    }

    /**
     * 专辑分页查询
     * @param albumTDTO
     * @return
     */
    @RequestMapping(value = "/findByPage",method = RequestMethod.POST)
    @ApiOperation(value = "/findByPage",notes = "专辑分页查询")
    public ResponseEntity findByPage(@RequestBody AlbumTDTO albumTDTO){
        try {
            return Response.success("查询成功", albumTService.findByPage(albumTDTO));
        } catch (WhyException e) {
            return Response.serverError(e.getMessage(), e.getCode());
        } catch (Exception e) {
            log.error("专辑分页查询出现异常，{}", e.getMessage());
            return Response.serverError(ResultEnum.UNERROR.getMessage(), ResultEnum.UNERROR.getCode());
        }
    }

}
